package nsn.message.aggregator.wizzards;

import java.util.Map;


import nsn.message.aggregator.model.IMessageAggregator;
import nsn.message.aggregator.model.ISourceType;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;

/**
 * 
 * @author Lukasz Nowak
 * @since 11-03-2011
 * 
 */
public class AddSourceWizard extends Wizard {

	private final IMessageAggregator _model;
	private NewSourcePage _newSourcePage = new NewSourcePage();

	private SelectSourceTypePage _selectSourceTypePage;
	private Map<String, String> _values;

	/**
	 * @param model
	 * 
	 */
	public AddSourceWizard(final IMessageAggregator model) {
		_model = model;
	}

	@Override
	public void addPages() {
		addPage(getSelectSourceTypePage());
		addPage(_newSourcePage);

	}

	@Override
	public IWizardPage getNextPage(IWizardPage page) {
		IWizardPage next = super.getNextPage(page);
		if (next instanceof NewSourcePage) {
			final ISourceType type = getSourceType();
			((NewSourcePage) next).setSourceType(type);
			((NewSourcePage) next).initLayout();
		}
		return next;
	}

	/**
	 * 
	 * @return boolean
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
	@Override
	public boolean performFinish() {
		_values = _newSourcePage.getValues();
		return _values != null;
	}

	/**
	 * 
	 * 
	 * @return Map<String, String>
	 */
	public Map<String, String> getValues() {
		return _values;
	}

	private SelectSourceTypePage getSelectSourceTypePage() {
		if (_selectSourceTypePage == null) {
			_selectSourceTypePage = new SelectSourceTypePage(_model);
		}
		return _selectSourceTypePage;
	}

	 /**
	 *
	 * @return SourceType
	 */
	public ISourceType getSourceType() {
		return getSelectSourceTypePage().getSourceType();


	}

}
